----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 41276 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 1024
SPELL.m_sName = "Shadow Stalk"
SPELL.m_sToolTip = "Gain 30 armor and 15% Dodge and Parry for 3 seconds. Costs 50 Energy."
SPELL.m_sIcon = "devin/blackbetty/spells/rogue/shadowstalk.png"
SPELL.m_iCoolDown = 1
SPELL.m_iManaCost = 50
SPELL.m_bRequiresTarget = true
SPELL.m_iSpellType = SPELLTYPE_MOBILITY
SPELL.m_bRecastWhileCasting = false

---------------------------------------------------------------------------------------

local range = 100
local weapondamage = 20

function SPELL:Cast( pl, target )
	print("Casted "..self.m_sName.."!")
	ParticleEffectAttach( "shadowstalk", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("anim_attachment_RH"))
	pl:EmitSound("devin/blackbetty/weapons/rogue/stealth.wav", 100, 100)
	pl.Dodge = pl.Dodge + 0.3
	
	local fadecounter = 0
	if(timer.Exists("shadowstalk_on_"..pl:EntIndex()..""))then
		timer.Destroy("shadowstalk_on_"..pl:EntIndex().."")
	end
	timer.Create("shadowstalk_on_"..pl:EntIndex().."", 1, 4, function() 
		pl:SetRenderMode(RENDERMODE_TRANSALPHA)
		pl:SetColor( Color(150-50*fadecounter, 150-50*fadecounter, 150-50*fadecounter, 150-50*fadecounter) )
		fadecounter = fadecounter + 1
		print(fadecounter)
	end)
	
	timer.Simple(3, function()
		pl:SetColor(Color(255, 255, 255, 255))
		pl:EmitSound("devin/blackbetty/weapons/rogue/shadowstep.wav", 100, 100)
		pl.Dodge = pl.Dodge - 0.3
		if(target:IsPlayer())then
			local b = AddEffect(target, 3, 2)
		end
		pl:SetPos(target:GetPos())
		pl:SetAngles(target:GetAngles())
		ParticleEffect( "shadowstep", pl:GetPos(), Angle(0,0,0), pl )
		ParticleEffect( "shadowstep", target:GetPos(), Angle(0,0,0), target )
		self:Effect(pl, target)
	end)
end

function SPELL:Effect(pl, target)

	local weapon = nil
	if(pl:IsPlayer())then
		weapon = pl:GetWeapon("weapon_all")
	else
		target = pl.Target
	end
	pl:EmitSound("devin/blackbetty/weapons/RendTarget.wav", 100, 80+math.random(-10,10))
	ParticleEffect( "pummel_hit", target:GetPos() + Vector(0, 0, 46) + (target:GetAngles():Forward()*6), Angle(0,0,0), pl )
	ParticleEffect( "player_blood", target:GetPos() + Vector(0, 0, 46) + (target:GetAngles():Forward()*6), Angle(0,0,0), pl )
	if(SERVER)then
		if(weapon)then
			self:DealDamage(weapon.MinWeaponDamage*1, weapon.MaxWeaponDamage*1, pl, target, DMG_GENERIC)
		else
			self:DealDamage(pl.MinDamage*1, pl.MaxDamage*1, pl, target, DMG_GENERIC)
		end
	end
end




